package com.xintai.hetong.controller;

import java.util.List;
import com.xintai.hetong.domain.ErpHetong;
import com.xintai.hetong.service.IErpHetongService;
import com.xintai.utils.MyGetCode;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xintai.common.annotation.Log;
import com.xintai.common.core.controller.BaseController;
import com.xintai.common.core.domain.AjaxResult;
import com.xintai.common.enums.BusinessType;
import com.xintai.common.utils.poi.ExcelUtil;
import com.xintai.common.core.page.TableDataInfo;

/**
 * 合同管理Controller
 *
 * @author xintai
 * @date 2021-01-27
 */
@RestController
@RequestMapping("/hetong/hetong")
public class ErpHetongController extends BaseController
{
    @Autowired
    private IErpHetongService erpHetongService;

    /**
     * 查询合同管理列表
     */
    @PreAuthorize("@ss.hasPermi('hetong:hetong:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpHetong erpHetong) throws Exception {
        List<ErpHetong> list = erpHetongService.selectErpHetongList(erpHetong);
        return getDataTable(list);
    }

    /**
     * 导出合同管理列表
     */
    @PreAuthorize("@ss.hasPermi('hetong:hetong:export')")
    @Log(title = "合同管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ErpHetong erpHetong)
    {
        List<ErpHetong> list = erpHetongService.selectErpHetongList(erpHetong);
        ExcelUtil<ErpHetong> util = new ExcelUtil<ErpHetong>(ErpHetong.class);
        return util.exportExcel(list, "hetong");
    }

    /**
     * 获取合同管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('hetong:hetong:query')")
    @GetMapping(value = "/{htId}")
    public AjaxResult getInfo(@PathVariable("htId") String htId)
    {
        return AjaxResult.success(erpHetongService.selectErpHetongById(htId));
    }

    /**
     * 新增合同管理
     */
    @PreAuthorize("@ss.hasPermi('hetong:hetong:add')")
    @Log(title = "合同管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpHetong erpHetong) {
        return toAjax(erpHetongService.insertErpHetong(erpHetong));
    }

    /**
     * 修改合同管理
     */
    @PreAuthorize("@ss.hasPermi('hetong:hetong:edit')")
    @Log(title = "合同管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpHetong erpHetong)
    {
        return toAjax(erpHetongService.updateErpHetong(erpHetong));
    }

    /**
     * 删除合同管理
     */
    @PreAuthorize("@ss.hasPermi('hetong:hetong:remove')")
    @Log(title = "合同管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{htIds}")
    public AjaxResult remove(@PathVariable String[] htIds)
    {
        return toAjax(erpHetongService.deleteErpHetongByIds(htIds));
    }
}